package org.czl.leetcode2;

public class l1423 {
    public int maxScore(int[] cardPoints, int k) {
        int n = cardPoints.length;
        int len = n - k;
        int sum = 0;
        int ans = Integer.MAX_VALUE;
        int all = 0;
        for(int i : cardPoints)all += i;
        if(k == n)return all;
        for(int i = 0; i < n; i++){
            sum += cardPoints[i];
            if(i < len - 1){
                continue;
            }
            ans = Math.min(ans, sum);
            sum -= cardPoints[i - len + 1];
        }
        return all - ans;
    }
}
